//
//  DJObservableController.swift
//  dj-learn-Swift
//
//  Created by Sun Jae on 2022/5/3.
//  Copyright © 2022 S.J. All rights reserved.
//

import UIKit
import RxSwift
import RxCocoa

class DJObservableController: DJViewController {
    
    var maybe: Maybe<String>?
    
    public func sj_create(subscribe: @escaping ( @escaping (Int) -> String ) -> String) -> Bool {
        

        return true
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "Observable"
       
        // Maybe 发出一个元素(success)或者一个完成事件(completeted)或者一个error事件
        maybe = Maybe.create { maybeObserver in
            // Maybe.create(subscribe: { (maybeObserver) -> Disposable in
            // 被订阅后才会执行里面的内容
            print(maybeObserver)
            maybeObserver(.success("hello world"))
            return Disposables.create {}
        }
 
        maybe?.subscribe(onSuccess: { (value) in
            print(value)
        }, onError: { (error) in
            print(error.localizedDescription)
        }, onCompleted: {
            print("completed")
        }).disposed(by: self.disposeBag)
        

        var success = self.sj_create { (value) -> String in
            return "value: \(value)"
        }
        
        
        self.sj_create { (inFunc) in
            
            var result = inFunc(1)
            
            return result
        }
    
    }
}
